package com.shopping.orm;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class SortDao extends HibernateDaoSupport {

private static final Log log = LogFactory.getLog(SortDao.class);
	
	public void save(Type instance){
		log.debug("saving Type instance");
		try{
		getHibernateTemplate().save(instance);
		log.debug("save Type successful");
		}catch(RuntimeException re){
			log.error("save Type failed",re);
			throw re;
		}
	}
	
	public void delete(Sort instance) {
        log.debug("deleting Sort instance");
        try {
            getHibernateTemplate().delete(instance);
            log.debug("delete Sort instance successful");
        } catch (RuntimeException re) {
            log.error("delete Sort instance failed", re);
            throw re;
        }
    }
	
	public void update(Sort instance){
		log.debug("Upate Sort instance");
		try{
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("update Sort instance  successful");
			
		}catch(RuntimeException re){
			log.error("update Sort instance failed",re);
			throw re;
		}
	}
	public List findByExample(Sort instance){
		log.debug("get Sort instance with +:example");
		try{
			List result = getHibernateTemplate().findByExample(instance);
			log.debug("get successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	public List findByproperty(String propertyName,Object value){
		log.debug("finding Sort instance with property:"+ propertyName + ",value:"+value);
		try {
		    String queryString = "from Sort as model where model." 
		         						+ propertyName + "= ?";
		    return getHibernateTemplate().find(queryString, value);
		}catch(RuntimeException re){
			log.error("find by property failed",re);
			throw re;
		}
	}
	
	
	public List findAll(){
		log.debug("getting Sort instance");		
		try{
			List result = getHibernateTemplate().findByExample("Sort");
			log.debug("find successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	
	public Sort findById(String uid){
		log.debug("get Sort instance with id:+uid");
		try{
			Sort instance = (Sort)getHibernateTemplate().get("Sort", uid);
			log.debug("get successful!");
			return instance;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}	
	}
	
	public List findBytypeId(String typeId){
		log.debug("get Sort instance with id:+uid");
		try{
			///Sort instance = (Sort)getHibernateTemplate().get("Sort", typeId);
			String hql = "from Sort where type_id='"+typeId+"'";
			List list = getHibernateTemplate().find("from Sort where type_id='"+typeId+"'");
			System.out.println("===========================");
			System.out.println(hql);
			System.out.println(typeId);
			log.debug("get successful!");
			return list;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}	
	}
}
